/*
 * Main.fx
 *
 * Created on 20.11.2002, 20:38:50
 */

package javafx179labs.Lebedev.lab4;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.animation.Timeline;
import javafx.scene.transform.Rotate;
import javafx.scene.input.MouseEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;


var fish1x = 70;
var fish1y = 180;
var fish1angle = 0;
var fish2x = 500;
var fish2y = 140;
var fish2angle = 0;
var eaty = -5;
/**
 * @author Lebedev
 */

var fish1 : ImageView = ImageView
{
    image: Image { url: "{__DIR__}fish1.png" }
    x: bind fish1x
    y: bind fish1y
    transforms: Rotate { pivotX : bind fish1x, pivotY : bind fish1y, angle: bind fish1angle }
    onMouseClicked: function(evt: MouseEvent):Void{
        timeline.playFromStart();
}

    }

var fish2 : ImageView = ImageView
{
    image: Image { url: "{__DIR__}fish2.png" }
    x: bind fish2x
    y: bind fish2y
    transforms: Rotate { pivotX : 640, pivotY : 245, angle: bind fish2angle }
    onMouseClicked: function(evt: MouseEvent):Void{
        timeline2.playFromStart();
}
}

var eat : Circle = Circle {
                centerX: 630, centerY: bind eaty
                radius: 3
                fill: Color.YELLOW
        }

var timeline : Timeline = Timeline{
    repeatCount:4
    autoReverse:false
    keyFrames: [
         at(2s){
            fish1x => 200;
            fish1y => 200;
            fish1angle => 5;
         }
         at(4s){
            fish1x => 500;
            fish1y => 180;
            fish1angle => -15;
         }
         at(5s){
            fish1x => 500;
            fish1y => 150;
            fish1angle => -80;
         }
         at(7s){
            fish1x => 300;
            fish1y => 160;
            fish1angle => -200;
         }
         at(9s){
            fish1x => 70;
            fish1y => 180;
            fish1angle => -360;
         }
        ]
}

var timeline2 : Timeline = Timeline{
    repeatCount:1
    autoReverse:false
    keyFrames: [
         at(3s){
            fish2angle => 90;
            eaty => -5;
         }
         at(7s){
            eaty => 240;
         }
         at(7s){
            eaty => 0;
         }
         at(14s){
            eaty => 240;
         }
         at(13s){
            fish2angle => 90;
         }
         at(15s){
            fish2angle => 0;
         }

        ]
}

Stage {
    title: "Application title"
    width: 749
    height: 404
    scene: Scene {
        content: [
            ImageView{
		    image: Image{
			       url:  "{__DIR__}background.jpg"
		     }

        }
        fish1,
        eat,
        fish2
        ]
    }
}